package com.modules.model;

import java.io.Serializable;
import java.util.Date;

import javax.persistence.Column;
import javax.persistence.EntityListeners;
import javax.persistence.MappedSuperclass;
import javax.persistence.PrePersist;
import javax.persistence.PreUpdate;
import javax.persistence.Temporal;
import javax.persistence.TemporalType;
import javax.persistence.Transient;
import javax.persistence.Version;

import org.springframework.data.jpa.domain.support.AuditingEntityListener;

import com.fasterxml.jackson.databind.annotation.JsonSerialize;
import com.modules.utils.DateConvertUtils;
import com.modules.utils.JsonDateSerializer;

/**
 * Created by lewis on 2017/7/15.
 */
@MappedSuperclass
@EntityListeners(AuditingEntityListener.class)
public abstract class SimpleModel implements Serializable {

    private static final long	serialVersionUID	= 1546045002472483990L;

    public static final String	DATE_FORMAT			= "yyyy-MM-dd";
    public static final String	TIME_FORMAT			= "HH:mm:ss";
    public static final String	DATE_TIME_FORMAT	= "yyyy-MM-dd HH:mm:ss";
    public static final String	TIMESTAMP_FORMAT	= "yyyy-MM-dd HH:mm:ss.S";

    public static final String	CREATED_BY_ID		= "createdById";
    public static final String	CREATED_BY_NAME		= "createdByName";
    public static final String	CREATED_TIME		= "createdTime";

    public static final String	MODIFIED_BY_ID		= "modifiedById";
    public static final String	MODIFIED_BY_NAME	= "modifiedByName";
    public static final String	MODIFIED_TIME		= "modifiedTime";

    public static final String	VERSION				= "version";
    public static final String	DELFLAG				= "delflag";
    public static final String	BIZ_STATUS			= "bizStatus";
    public static final String	DISPLAY_ORDER		= "displayOrder";
    public static final String	BIZ_TAG1			= "bizTag1";
    public static final String	BIZ_TAG2			= "bizTag2";
    public static final String	BIZ_TAG3			= "bizTag3";

    public static final String	BIZ_UNIT_CODE		= "bizUnitCode";
    public static final String	BIZ_UNIT_NAME		= "bizUnitName";
    public static final String	BIZ_GROUP_CODE		= "bizGroupCode";
    public static final String	BIZ_GROUP_NAME		= "bizGroupName";
    public static final String	BIZ_OWNER_CODE		= "bizOwnerCode";
    public static final String	BIZ_OWNER_NAME		= "bizOwnerName";

    public static final String	DELFLAG_N			= "N";
    public static final String	DELFLAG_Y			= "Y";


    @Version
    @Column(name = "VERSION_")
    private Integer				version;										// 乐观锁版本标记
    @Column(name = "DELFLAG_", length = 1)
    private String				delflag;										// 逻辑删除标记Y/N,默认值N
    @Column(name = "CREATED_BY_ID_", length = 64, updatable = false)
    private String				createdById;									// 创建人ID
    @Column(name = "CREATED_BY_NAME_", length = 64, updatable = false)
    private String				createdByName;									// 创建人名称
    @Temporal(TemporalType.TIMESTAMP)
    @Column(name = "CREATED_TIME_", updatable = false)
    private Date createdTime;									// 创建时间
    @Column(name = "MODIFIED_BY_ID_", length = 64)
    private String				modifiedById;									// 最后修改人ID
    @Column(name = "MODIFIED_BY_NAME_", length = 64)
    private String				modifiedByName;								// 最后修改人名称
    @Temporal(TemporalType.TIMESTAMP)
    @Column(name = "MODIFIED_TIME_")
    private Date				modifiedTime;									// 最后修改时间
    @Column(name = "DISPLAY_ORDER_")
    private Integer				displayOrder;									// 显示顺序号
    @Column(name = "ACCOUNT_NO_", length = 64)
    private String				accountNo;										// 帐套号

    @Column(name = "BIZ_STATUS_", length = 64)
    private String				bizStatus;										// 业务状态，使用者自己定义其用途，对应的wfStatus是专门给流程审批用的
    @Column(name = "BIZ_TAG1_", length = 64)
    private String				bizTag1;										// 业务标记1，使用者自己定义其用途
    @Column(name = "BIZ_TAG2_", length = 64)
    private String				bizTag2;										// 业务标记2，使用者自己定义其用途
    @Column(name = "BIZ_TAG3_", length = 64)
    private String				bizTag3;										// 业务标记3，使用者自己定义其用途

    //为所有的表添加业务数据所在的部室、部门和机构信息，一般都是用来控制数据权限的。
    @Column(name = "BIZ_UNIT_CODE_", length = 64)
    private String				bizUnitCode;									// 业务数据所在部室编码
    @Column(name = "BIZ_UNIT_NAME_", length = 256)
    private String				bizUnitName;									// 业务数据所在部室名称
    @Column(name = "BIZ_GROUP_CODE_", length = 64)
    private String				bizGroupCode;									// 业务数据所在部门编码
    @Column(name = "BIZ_GROUP_NAME_", length = 256)
    private String				bizGroupName;									// 业务数据所在部门名称
    @Column(name = "BIZ_OWNER_CODE_", length = 64)
    private String				bizOwnerCode;									// 业务数据所在机构编码
    @Column(name = "BIZ_OWNER_NAME_", length = 256)
    private String				bizOwnerName;									// 业务数据所在机构名称

    @Transient
    private String				checkbox;										// 专门供前端grid中显示checkbox用的，和数据库没有关系 gyzhang@20131128@nanhai

    public Integer getVersion() {
        return version;
    }

    public void setVersion(Integer version) {
        this.version = version;
    }

    public String getDelflag() {
        return delflag;
    }

    public void setDelflag(String delflag) {
        this.delflag = delflag;
    }

    public String getCreatedById() {
        return createdById;
    }

    public void setCreatedById(String createdById) {
        this.createdById = createdById;
    }

    public String getCreatedByName() {
        return createdByName;
    }

    public void setCreatedByName(String createdByName) {
        this.createdByName = createdByName;
    }

    @JsonSerialize(using = JsonDateSerializer.class)
    public Date getCreatedTime() {
        return createdTime;
    }

    public void setCreatedTime(Date createdTime) {
        this.createdTime = createdTime;
    }
    @Transient
    public String getCreatedTimeString() {

        return DateConvertUtils.format(getCreatedTime(), DATE_FORMAT);
    }

    public void setCreatedTimeString(String value) {
        setCreatedTime(DateConvertUtils.parse(value, DATE_FORMAT, Date.class));
    }


    public String getModifiedById() {
        return modifiedById;
    }

    public void setModifiedById(String modifiedById) {
        this.modifiedById = modifiedById;
    }

    public String getModifiedByName() {
        return modifiedByName;
    }

    public void setModifiedByName(String modifiedByName) {
        this.modifiedByName = modifiedByName;
    }

    @JsonSerialize(using = JsonDateSerializer.class)
    public Date getModifiedTime() {
        return modifiedTime;
    }

    public void setModifiedTime(Date modifiedTime) {
        this.modifiedTime = modifiedTime;
    }


    @Transient
    public String getModifiedTimeString() {
        return DateConvertUtils.format(getModifiedTime(), DATE_FORMAT);
    }

    public void setModifiedTimeString(String value) {
        setModifiedTime(DateConvertUtils.parse(value, DATE_FORMAT, Date.class));
    }


    public String getAccountNo() {
        return accountNo;
    }

    public void setAccountNo(String accountNo) {
        this.accountNo = accountNo;
    }

    public String getBizStatus() {
        return bizStatus;
    }

    public void setBizStatus(String bizStatus) {
        this.bizStatus = bizStatus;
    }

    public Integer getDisplayOrder() {
        return displayOrder;
    }

    public void setDisplayOrder(Integer displayOrder) {
        this.displayOrder = displayOrder;
    }

    public String getBizTag1() {
        return bizTag1;
    }

    public void setBizTag1(String bizTag1) {
        this.bizTag1 = bizTag1;
    }

    public String getBizTag2() {
        return bizTag2;
    }

    public void setBizTag2(String bizTag2) {
        this.bizTag2 = bizTag2;
    }

    public String getBizTag3() {
        return bizTag3;
    }

    public void setBizTag3(String bizTag3) {
        this.bizTag3 = bizTag3;
    }

    public String getBizUnitCode() {
        return bizUnitCode;
    }

    public void setBizUnitCode(String bizUnitCode) {
        this.bizUnitCode = bizUnitCode;
    }

    public String getBizUnitName() {
        return bizUnitName;
    }

    public void setBizUnitName(String bizUnitName) {
        this.bizUnitName = bizUnitName;
    }

    public String getBizGroupCode() {
        return bizGroupCode;
    }

    public void setBizGroupCode(String bizGroupCode) {
        this.bizGroupCode = bizGroupCode;
    }

    public String getBizGroupName() {
        return bizGroupName;
    }

    public void setBizGroupName(String bizGroupName) {
        this.bizGroupName = bizGroupName;
    }

    public String getBizOwnerCode() {
        return bizOwnerCode;
    }

    public void setBizOwnerCode(String bizOwnerCode) {
        this.bizOwnerCode = bizOwnerCode;
    }

    public String getBizOwnerName() {
        return bizOwnerName;
    }

    public void setBizOwnerName(String bizOwnerName) {
        this.bizOwnerName = bizOwnerName;
    }

    public String getCheckbox() {
        return checkbox;
    }

    public void setCheckbox(String checkbox) {
        this.checkbox = checkbox;
    }
    
    @PrePersist
    public void prePersist() {
    	//插入时执行的方法
        this.setAccountNo("1111111111111111");
    }
    
    @PreUpdate
    public void preUpdate() {
    	//更新时执行的方法
    	
    }

}